﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using ProjectVLIB.VOL;
using System.Data;
using ProjectVLIB.DAL;

namespace ProjectVLIB.BLL
{
    class DMKhachBL
    {
        private DataAccess dataAccess;
        public DMKhachBL()
        {
            dataAccess = new DataAccess();
        }

        //Thêm
        public bool insertDMKhach(DMKhach obj)
        {
            SqlParameter[] param = new SqlParameter[4];
            param[0] = new SqlParameter("@HoTen", SqlDbType.NVarChar) { Value = obj.HoTen };
            param[1] = new SqlParameter("@DiaChi", SqlDbType.NVarChar) { Value = obj.DiaChi };
            param[2] = new SqlParameter("@DienThoai", SqlDbType.VarChar) { Value = obj.DienThoai };
            param[3] = new SqlParameter("@Email", SqlDbType.NVarChar) { Value = obj.Email };

            string strSql = "INSERT INTO tbl_DMKhach(HoTen,DiaChi,DienThoai,Email) VALUES (@HoTen,@DiaChi,@DienThoai,@Email)";
            dataAccess.Execute(strSql);

            return true;
        }

        //Xóa
        public bool deleteDMKhach(DMKhach obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaKhach", SqlDbType.Int) { Value = obj.MaKhach };

            string strSql = "DELETE FROM tbl_DMKhach WHERE MaKhach = @MaHaMaKhachng";
            dataAccess.Execute(strSql);
            return true;
        }

        //Sửa
        public bool updateDMKhach(DMKhach obj)
        {
            SqlParameter[] param = new SqlParameter[5];
            param[0] = new SqlParameter("@HoTen", SqlDbType.NVarChar) { Value = obj.HoTen };
            param[1] = new SqlParameter("@DiaChi", SqlDbType.NVarChar) { Value = obj.DiaChi };
            param[2] = new SqlParameter("@DienThoai", SqlDbType.VarChar) { Value = obj.DienThoai };
            param[3] = new SqlParameter("@Email", SqlDbType.NVarChar) { Value = obj.Email };
            param[4] = new SqlParameter("@MaKhach", SqlDbType.NVarChar) { Value = obj.MaKhach };

            string strSql = "UPDATE tbl_DMKhach SET " +
                            "HoTen = @HoTen, " +
                            "DiaChi = @DiaChi, " +
                            "DienThoai = @DienThoai, " +
                            "Email = @Email " +
                            "WHERE MaKhach = @MaKhach";
            dataAccess.Execute(strSql);
            return true;
        }

        //Tìm
        public DataTable searchIDDMKhach(DMKhach obj)
        {
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@MaKhach", SqlDbType.Int) { Value = obj.MaKhach };

            string strSql = "SELECT * FROM tbl_DMKhach WHERE MaKhach = @MaKhach";
            return dataAccess.GetData(strSql, param);
        }
    }
}
